package com.buchouwang.xiongmaitech.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @program: spring_boot_Demo
 * @description: restTemplate配置类
 * spring boot Calling REST Services with RestTemplate
 * https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-resttemplate.html#boot-features-resttemplate
 * 使用RestTemplateBuilder 创建的RestTemplate 避免乱码情况的发生 否则需要手动的修改RestTemplate编码规则
 * @author: ace
 * @Date: 2020-04-13 20:36
 */
@Configuration
public class RestTemplateConfig {
    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    /**
     * rootUri
     * Set a root URL that should be applied to each request that starts with '/'.
     * https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/api/
     * @return
     */
    @Bean
    public RestTemplate restTemplate(){
        return restTemplateBuilder
                .rootUri("http://ls.cmobd.com/be-cwt-api/api")
                .build();
    }
}